#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2025 Huawei Technologies Co., Ltd. All rights reserved.

from ansible.module_utils.basic import AnsibleModule

from openubmc_ansible.openubmc_logger import log
from openubmc_ansible.openubmc_logger import report
from openubmc_ansible.openubmc_redfish_api.api_basic_info import get_basic_info
from openubmc_ansible.openubmc_redfish_api.redfish_base import BmcBaseConnect
from openubmc_ansible.utils import ansible_bmc_run_module


ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = r'''
---
module: openubmc_get_basic_info
short_description: Get server information
version_added: "2.5.0"
description:
    - Obtain the openUBMC, BIOS, CPLD version and SP, CPU, memory, drive information
options:
    openubmc_ip:
        required: true
        default: None
        description:
            - openUBMC IP address
    openubmc_user:
        required: true
        default: None
        description:
            - openUBMC user name used for authentication
    openubmc_pswd:
        required: true
        default: None
        description:
            - openUBMC user password used for authentication
    csv_format:
        required: false
        default: False
        choices: [ True, False ]
        description:
            - Whether to write the result to a CSV file
'''

EXAMPLES = r'''
- name: get openubmc basic info
  openubmc_get_basic_info:
    openubmc_ip: "{{ openubmc_ip }}"
    openubmc_user: "{{ openubmc_user }}"
    openubmc_pswd: "{{ openubmc_pswd }}"
    csv_format: True
'''

RETURNS = r'''
    "msg": "Get basic info successful!"
'''


def openubmc_get_basic_info(module):
    """
    Function:
        Get Server basic info
    Args:
        module       (class):
    Returns:
        {"result": False, "msg": ''}
    Raises:
        None
    Examples:

    Author:
    Date: 2019/11/23 15:11
    """
    ret = {"result": False, "msg": 'not run get basic info yet'}
    with BmcBaseConnect(module.params, log, report) as openubmc:
        ret = get_basic_info(openubmc, module.params.get("csv_format"))
    return ret


def main():
    module = AnsibleModule(
        argument_spec={
            "openubmc_ip": {"required": True, "type": 'str'},
            "openubmc_user": {"required": True, "type": 'str'},
            "openubmc_pswd": {"required": True, "type": 'str', "no_log": True},
            "csv_format": {"required": False, "type": 'bool'}
        },
        supports_check_mode=False)
    ansible_bmc_run_module(openubmc_get_basic_info, module, log, report)


if __name__ == '__main__':
    main()
